* Authors:
* Program written by Bolin, Song (松柏林) Shenzhen , China.
* Wechat:songbl_stata, 2021-01-02
* Please do not use this code for commerical purpose

capture program drop sbl
program define sbl
	version 15.0
syntax anything  (name = pkgname ) 
    tokenize `pkgname'
    if "`2'"!= ""{
    di as err  `"sbl install: "`pkgname'" not found at SBL, type {stata ssc install `pkgname'}"'
    exit 601
    }
    local URL "https://gitee.com/songbolin/stata_ado/raw/master/"
    local PATH           `"`c(sysdir_plus)'"'        
    local path           =substr("`pkgname'",1,1) 
    local PATH           `PATH'\`path'\ 
    cap mkdir `"`PATH'"'        
        
    cap copy  "`URL'`pkgname'.ado"   "`PATH'\`pkgname'.ado"         ,replace
        while _rc ~= 0 {
			local times = `times' + 1
			sleep 1000
			cap copy  "`URL'`pkgname'.ado"   "`PATH'\`pkgname'.ado"     ,replace 
			if `times' > 10 {
				di as err  `"sbl install: "`pkgname'" not found at SBL, type {stata ssc install `pkgname'}"'
                exit 601
			}
		}                     
    local cla  hlp  sthlp 
    foreach j in `cla'{
        cap copy  "`URL'`pkgname'.`j'"   "`PATH'\`pkgname'.`j'"       ,replace
    }
    cap copy  "`URL'cn_`pkgname'.sthlp"   "`PATH'cn_`pkgname'.sthlp"     ,replace 
    dis as  yellow "The download is complete"
    *local cla  c class css csv dir dlg do docx dta hlp html idlg ihlp ini    ///
    *js mata mlib mo pkl plu plugin png pref py sas scheme stbcal sthlp style ///
    *tex txt zip

end